﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.GOLD;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord.Queries;
using AjaxPro;
using Common;
namespace Mang24k99.Business.GOLD
{
    public partial class BKtGoldImportprice
    {
        /// <summary>
        /// Creates the before.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>if true Cancel</returns>
        private static bool CreateBefore(MKtGoldImportprice model)
        {
            return false;
        }

        /// <summary>
        /// Creates the after.
        /// </summary>
        /// <param name="model">The model.</param>
        private static void CreateAfter(MKtGoldImportprice model)
        {
            
        }
        /// <summary>
        /// Updates the before.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>if true Cancel</returns>
        private static bool UpdateBefore(MKtGoldImportprice model)
        {
            return false;
        }
        /// <summary>
        /// Updates the after.
        /// </summary>
        /// <param name="model">The model.</param>
        private static void UpdateAfter(MKtGoldImportprice model)
        {
            
        }

        /// <summary>
        /// Deletes the before.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>if true Cancel</returns>
        private static bool DeleteBefore(MKtGoldImportprice model)
        {
            return false;
        }
        /// <summary>
        /// Deletes the after.
        /// </summary>
        /// <param name="model">The model.</param>
        private static void DeleteAfter(MKtGoldImportprice model)
        {
            ;
        }


        //public static int Count(string name,string unit)
        //{
        //    ICriterion[] criteria = new ICriterion[]
        //    {
        //        Expression.Eq("IsValidate",1),
        //        Expression.Eq("ProductName",name),
        //        Expression.Eq("ProductUnit",unit),
        //    };
        //    return MKtGoldImportprice.Counts(criteria);
        //}

        public static int Count(int codeno)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
                Expression.Eq("MParentKtCommCodelistByPriceType.CODE_NO",codeno),                
            };
            return MKtGoldImportprice.Counts(criteria);
        }



        public static int Count2(string name)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
                Expression.Eq("ProductName",name),                
            };
            return MKtGoldImportprice.Counts(criteria);
        }

        public static MKtGoldImportprice FindFirstData(string name, string unit)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                 Expression.Eq("ProductName",name),
                 Expression.Eq("ProductUnit",unit),
            };
            return MKtGoldImportprice.SelectFirst(criteria);
        }
        public static MKtGoldImportprice FindFirstData2(string name, int codeno)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                 Expression.Eq("ProductName",name),  
                 Expression.Eq("MParentKtCommCodelistByPriceType.CODE_NO",codeno), 
            };
            return MKtGoldImportprice.SelectFirst(criteria);
        }

        public static void Deletes(int codeno)
        {
            string where = " pricetype = " + codeno;
           MKtGoldImportprice.Deletes(where);

        }


        public static IList<MKtGoldImportprice> FindAll(int codeno)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
               Expression.Eq("MParentKtCommCodelistByPriceType.CODE_NO",codeno), 
            };
            return MKtGoldImportprice.SelectAll(criteria);
        }
        

    }
}
